package com.jiantong.work.impl.service.yangzhibaoxian;

/**
 * Created by ThinkPad on 2017/9/5.
 */


import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.yangzhibaoxian.ClaimsSettlementDao;
import com.jiantong.work.impl.dao.yangzhibaoxian.InsuranceApplicationDao;
import com.jiantong.work.model.yangzhibaoxian.ClaimsResult;
import com.jiantong.work.model.yangzhibaoxian.ClaimsSettlement;
import com.jiantong.work.service.yangzhibaoxian.ClaimsSettlementService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.PageInfo;
import io.terminus.common.model.Paging;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 理赔单申请单
 */
@Slf4j
@Service
@RpcProvider
public class ClaimsSettlementServiceImpl implements ClaimsSettlementService{
    private ClaimsSettlementDao claimsSettlementDao;

    @Autowired
    public ClaimsSettlementServiceImpl(ClaimsSettlementDao claimsSettlementDao) {
        this.claimsSettlementDao = claimsSettlementDao;
    }

    @Override
    public Response<ClaimsSettlement> findById(Long id) {
        try {
            ClaimsSettlement claimsSettlement = (ClaimsSettlement) claimsSettlementDao.findById(id);
            if (claimsSettlement == null) {
                log.error("claimsSettlement(id={}) is not found", id);
                return Response.fail("claimsSettlement.not.found");
            }

            return Response.ok(claimsSettlement);
        } catch (Exception e) {
            log.error("failed to find claimsSettlement(id={}), cause:{}", id, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsSettlement.find.fail");
        }
    }

    @Override
    public Response<List<ClaimsSettlement>> findByIds(List ids) {
        try {
            List<ClaimsSettlement> claimsSettlementList=  claimsSettlementDao.findByIds(ids);
            if (claimsSettlementList == null) {
                log.error("claimsSettlementList(ids={}) is not found", ids);
                return Response.fail("claimsSettlementList.not.found");
            }

            return Response.ok(claimsSettlementList);
        } catch (Exception e) {
            log.error("failed to find claimsSettlementList(ids={}), cause:{}", ids, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsSettlementList.find.fail");
        }

    }

    @Override
    public Response<List<ClaimsSettlement>> list(Map map) {
        try {
            List<ClaimsSettlement> claimsSettlementList=  claimsSettlementDao.list(map);
            if (claimsSettlementList == null) {
                log.error("claimsSettlementList(ids={}) is not found", map);
                return Response.fail("claimsSettlementList.not.found");
            }

            return Response.ok(claimsSettlementList);
        } catch (Exception e) {
            log.error("failed to find claimsSettlementList(ids={}), cause:{}", map, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsSettlementList.find.fail");
        }
    }

    @Override
    public Response<Paging<ClaimsSettlement>> ping(Integer offset, Integer limit, Map map) {
        try {
            PageInfo pageInfo=new PageInfo(offset,limit);
            Paging<ClaimsSettlement> claimsSettlementPaging=   claimsSettlementDao.paging(pageInfo.getOffset(), pageInfo.getLimit(),map);
            if (claimsSettlementPaging == null) {
                log.error("claimsLossPaging(ids={}) is not found", map);
                return Response.fail("claimsLossPaging.not.found");
            }

            return Response.ok(claimsSettlementPaging);
        } catch (Exception e) {
            log.error("failed to find claimsSettlementPaging(ids={}), cause:{}", map, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsLossPaging.find.fail");
        }
    }

    @Override
    public Boolean update(ClaimsSettlement claimsSettlement) {
        try {
            Boolean b= claimsSettlementDao.update(claimsSettlement);
            return b;
        }catch (Exception e){
            return false;
        }
    }

    @Override
    public Long create(ClaimsSettlement claimsSettlement) {
        try {
            claimsSettlementDao.create(claimsSettlement);
            return claimsSettlement.getId();
        }catch (Exception e){
            e.printStackTrace();
            return -500L;
        }
    }

    @Override
    public Integer creates(List<ClaimsSettlement> claimsSettlementList) {
        try {

            return   claimsSettlementDao.creates(claimsSettlementList);
        }catch (Exception e){
            e.printStackTrace();
            return -500;
        }
    }


}
